package microcredit.gui.table.impl;

import java.util.Date;

import microcredit.gui.table.EnumBeanTableModel;
import microcredit.gui.util.FormatUtilities;
import microcredit.model.MemberToLoanHistory;
import microcredit.model.util.ModelUtils;

enum LoanHistoryColumns {
	SEQUENCE, START_DATE, WEEKS, REASON, TEXT 
}
public class LoanHistoryTableModel  extends EnumBeanTableModel<MemberToLoanHistory, LoanHistoryColumns> {

	@Override
	protected Object getValue(MemberToLoanHistory o, LoanHistoryColumns column) {
		switch (column) {
		case START_DATE : return o.getStartDate();
		case REASON : return o.getExtensionReason() == null ? " - " : o.getExtensionReason().toString();
		case SEQUENCE : return o.getHistorySequenceID() != null ? ModelUtils.formatID(o.getHistorySequenceID()+1, 4) : null;
		case TEXT : return o.getReasonText() == null ? " - " : o.getReasonText();
		case WEEKS : return o.getNewNumberOfWeeks();
		}
		return null;
	}

	@Override
	protected int getWidth(LoanHistoryColumns column) {
		switch (column) {
		case START_DATE : return 60;
		case REASON : return 100;
		case SEQUENCE : return 10; 
		case TEXT : return 100;
		case WEEKS : return 20;
		}
		return 0;
	}
	
	@Override
	protected Object getFormat(MemberToLoanHistory o, LoanHistoryColumns column) {
		switch (column) {
		case START_DATE : return FormatUtilities.getDateFormat();
		}
		return null;
	}
	
	@Override
	protected Class<?> getValueClass(LoanHistoryColumns column) {
		switch (column) {
		case START_DATE : return Date.class;
		case WEEKS : return Integer.class; 
		}
		return super.getValueClass(column);
	}
	
	@Override
	protected String getName(LoanHistoryColumns column) {
		switch (column) {
		case START_DATE : return "Start date";
		case REASON : return "Extension reason";
		case SEQUENCE : return "No";
		case TEXT : return "Reason text";
		case WEEKS : return "Weeks";
		}
		return null;
	}

}
